using System;
using Com.Modules.AdminModule.Entities;
using Com.Modules.AdminModule.Repositories.Abstractions;
using SqlSugar;

namespace Com.Modules.AdminModule.Repositories.Implementations;

public class AdminRepository:IAdminRepository
{
    private readonly ILogger<AdminRepository> _logger;
    private readonly ISqlSugarClient _db;
    public AdminRepository(
        ILogger<AdminRepository> logger
        , ISqlSugarClient db
    ) {
        _logger = logger;
        _db = db;
    }


#region 查询用户
    // 根据Token查询用户
    public async Task<AdminEntity?> GetAdminByToken(string token) {
        return await _db.Queryable<AdminEntity>()
            .Where(a => a.IsDelete == 0)
            .Where(a => a.Token == token)
            .FirstAsync();
    }
#endregion


#region 记录查询
#endregion


#region 统计查询
#endregion


#region 列表查询
#endregion


#region 判断
#endregion


#region 增改删
    // 更新Token过期时间
    public async Task<bool> UpdateTokenExpireTime(int id, DateTime expireTime) {
        return await _db.Updateable<AdminEntity>()
            .SetColumns(a => new AdminEntity { TokenExpireTime = expireTime })
            .Where(a => a.Id == id)
            .ExecuteCommandAsync() == 1;
    }
#endregion
}
